﻿using Kimd.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WorkStation.Common
{
    public class UserInfo
    {
        public SerializableDictionary<int, string> Role2Password { get; set; }
        /// <summary>
        /// 0-Op,1-Eng,2-Admin
        /// </summary>
        public int UserLevel { get; set; }
        public Action OnUserRoleChanged { get; set; }
        public UserInfo()
        {
            Role2Password = new SerializableDictionary<int, string>();
            Role2Password.Add(0, "op");
            Role2Password.Add(1, "engineer");
            Role2Password.Add(2, "admin");
        }
        public bool Verify(string name, string password)
        {
            switch(name)
            {
                case "作业员":
                    UserLevel = 0;
                    if (OnUserRoleChanged != null)
                        OnUserRoleChanged();
                    return true;
                case "工程师":
                    if (password.Equals(Role2Password[1]))
                    {
                        UserLevel = 1;
                        if (OnUserRoleChanged != null)
                            OnUserRoleChanged();
                        return true;
                    }
                    else
                        return false;
                case "管理员":
                    if (password.Equals(Role2Password[2]))
                    {
                        UserLevel = 2;
                        if (OnUserRoleChanged != null)
                            OnUserRoleChanged();
                        return true;
                    }
                    else
                        return false;
            }
            return false;
        }
        public override string ToString()
        {
            string role = "";
            if (UserLevel == 0)
                role = "作业员";
            else if (UserLevel == 1)
                role = "工程师";
            else if (UserLevel == 2)
                role = "管理员";
            return role;
        }
    }
}
